<template>
	<!-- 商品推荐 -->
	<view class="goods-block">
		<view class="title">
			<uni-icons type="list"></uni-icons>
			<text>{{title}}</text>
		</view>

		<view style="display:flex;flex-direction:row;flex-wrap: wrap;">
			<view style="width:calc(100%/3);" v-for="(item, i) in goodsList" :key="i" @click="onDetail(item.goodsId)">
				<view class="goods-item">
					<!-- 图片 -->
					<image :src="item.goodsImg" style="width: 100%; height:100px;" mode="aspectFit" />
					<!-- 商品名 -->
					<div class="goods-name">{{ item.goodsName }}</div>
					<!-- 单价 -->
					<div class="price">￥{{ item.goodsPrice.toFixed(2) }}</div>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'homeGoods',
		props: {
			goodsList: Array,
			title: String
		},
		methods: {
			onDetail(goodsId) {
				uni.navigateTo({
					url: `/pages/goods/goodsDetail?goodsId=${goodsId}`
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	.goods-block {
		display: flex;
		flex-direction: column;
		background-color: $uni-bg-color-grey;
	}

	.title {
		font-size: 16px;
		background-color: $uni-bg-color-hover;
		align-items: center;
		padding: 5px;
	}

	.goods-item {
		display: flex;
		flex-direction: column;
		background-color: white;
		margin: 5px;
		padding: 5px;
		border-radius: 10px;
		font-size: 12px;

		.goods-name {
			margin: 10px 0;
			display: -webkit-box;
			/*弹性伸缩盒子模型显示*/
			-webkit-box-orient: vertical;
			/*排列方式*/
			-webkit-line-clamp: 2;
			/*显示文本行数(这里控制多少行隐藏)*/
			overflow: hidden;
			/*溢出隐藏*/
		}
	}

	.price {
		font-size: 14px;
		font-weight: bold;
		color: red;
		text-align: right;
	}
</style>